<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <script src="./ajax.js"></script>
    <script>
        function reloadImage(img) {
            img.src = "/shop/pngImg.php?t=" + Math.random();
        }
        function doLogin(){
            let arr = document.querySelectorAll("input[name]");
            let params = "";
            arr.forEach(ele => {
                params += ele.name + "=" + ele.value + "&";
                // console.log(str);
            });
            params = params.substr(0, params.length - 1);
            console.log('params:', params);
            ajax({
                url: "/shop/doLogin.php",
                data: params,
                method: "post",
                success: function(result) {
                    console.log(result);
                    alert(result.msg);
                    if(result.success){
                        // 登录成功, 跳转首页
                        location.href = "/shop/productManage.php";
                    }
                }
            });
        }
    </script>
</head>
<body>
    <h2>登录</h2>
    <form action="/shop/doLogin.php" method="POST" onsubmit=" return true; ">
        <div>
            <label>登录名: <input type="text" name="loginName" ></label>
        </div>
        <div>
            <label>密码: <input type="password" name="pwd" ></label>
        </div>
        <div>
            <label>
                验证码: <input type="text" name="userCode" >
                <img src="/shop/pngImg.php" onclick="reloadImage(this)" alt="验证码加载失败" title="点击刷新验证码" >
            </label>
        </div>
        <div>
            <input type="button" onclick="doLogin()" value="登录">
        </div>
    </form>
</body>
</html>